#include <stdio.h>

int main_18()
{
    int n,left,cur,j,right,cnt=0;
    scanf("%d%d%d",&n,&left,&cur);
    for (j=2; j<n ; j++ )
    {
        scanf("%d",&right);
        if ((cur>left&&cur>right)||(cur<left&&cur<right))
        {
            cnt++;
        }
        left=cur;
        cur=right;
    }
    printf("%d\n",cnt);
    return 0;
}
